package com.mzq.langchain4j_springboot.web.service.Impl;

import com.mzq.langchain4j_springboot.web.entity.MaintenanceRecord;
import com.mzq.langchain4j_springboot.web.mapper.MaintenanceRecordMapper;
import com.mzq.langchain4j_springboot.web.service.MaintenanceRecordService;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 维护记录Service实现类
 */
@Service
public class MaintenanceRecordServiceImpl implements MaintenanceRecordService {

    @Resource
    private MaintenanceRecordMapper maintenanceRecordMapper;

    @Override
    public int insertMaintenanceRecord(MaintenanceRecord maintenanceRecord) {
        return maintenanceRecordMapper.insertMaintenanceRecord(maintenanceRecord);
    }

    @Override
    public int updateMaintenanceRecord(MaintenanceRecord maintenanceRecord) {
        return maintenanceRecordMapper.updateMaintenanceRecord(maintenanceRecord);
    }

    @Tool("根据维修报告ID查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportById(
            @P("维修报告ID") String id
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setId(id);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据工单号查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByWorkOrder(
            @P("工单号") String workOrder
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setWorkOrder(workOrder);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据房产编号查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByHouseNumber(
            @P("房产编号") String houseNumber
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setHouseNumber(houseNumber);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据维修状态查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByMaintenanceStatus(
            @P("维修状态") String maintenanceStatus
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setMaintenanceStatus(maintenanceStatus);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据工单状态查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByOrderStatus(
            @P("工单状态") String orderStatus
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setOrderStatus(orderStatus);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据负责单位查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByDeptId(
            @P("负责单位") String deptId
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setDeptId(deptId);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据负责人_维修人查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByHeadId(
            @P("负责人_维修人") String headId
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setHeadId(headId);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据创建时间查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByCreateTime(
            @P("创建时间") String createTime
    ) throws ParseException {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setCreateTime(createTime);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据创建人查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByCreateBy(
            @P("创建人") String createBy
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setCreateBy(createBy);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据工单完成时间查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByFinishTime(
            @P("工单完成时间") String finishTime
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setFinishTime(finishTime);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据审批状态查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByApprovalStatus(
            @P("审批状态") String approvalStatus
    ) {
         MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setApprovalStatus(approvalStatus);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据工单类型查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByWorkType(
            @P("工单类型") String workType
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setWorkType(workType);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据备注查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByRemark(
            @P("备注") String remark
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setRemark(remark);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据维修项目查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByMaintenanceItems(
            @P("维修项目") String maintenanceItems
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setMaintenanceItems(maintenanceItems);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据计划完成时间查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByPlannedFinishTime(
            @P("计划完成时间") String plannedFinishTime
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setPlannedFinishTime(plannedFinishTime);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据关联巡检工单查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByBusinessWorkOrder(
            @P("关联巡检工单") String businessWorkOrder
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setBusinessWorkOrder(businessWorkOrder);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据模块类型查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByModuleType(
            @P("模块类型") String moduleType
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setModuleType(moduleType);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据工单名称查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByWorkName(
            @P("工单名称") String workName
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setWorkName(workName);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据维护记录_房屋ID查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByHouseId(
            @P("维护记录_房屋ID") String houseId
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setHouseId(houseId);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }

    @Tool("根据用户ID查询维修报告信息")
    public List<Map<String, Object>> getMaintenanceReportByUserId(
            @P("用户ID") String UserId
    ) {
        MaintenanceRecord mr = new  MaintenanceRecord();
        mr.setUserId(UserId);
        return maintenanceRecordMapper.selectMaintenanceRecordList(mr);
    }
}
